import pymysql
class MysqlHelper(object):
    #需要有mysql 的连接
    #需要有游标cursor
    def __init__(self):
        self.conn = pymysql.connect(host = '127.0.0.1',
                                    port = 3306,user = 'root',
                                    passwd = 'root', db = 'py18',
                                    charset = 'utf8'
                                    )
        self.cursor = self.conn.cursor()

    def execute_modify_sql(self,sql,data):
        self.cursor.execute(sql,data)
        self.conn.commit()

    def __del__(self):
        self.cursor.close()
        self.conn.close()

if __name__ == '__main__':
    helper = MysqlHelper()
    insert_sql ='insert into weibo_test(weibo_text)values (%s)'
    data = ('我是第一条',)
    helper.execute_modify_sql(insert_sql,data)